package com.sf.template.jdbc;

import javax.sql.DataSource;
import java.sql.ResultSet;
import java.util.List;

/**
 * @author 埔枘
 * @date 2019/12/02
 **/
public class UserDao extends JdbcTemplate<User>{

    public UserDao(DataSource dataSource) {
        super(dataSource);
    }

    public List<User> findAll(){
        List<User> objects = super.executeQuery("select * from sys_user", new RowMapper<User>() {
            @Override
            public User mapRow(ResultSet rs, int rowNum) throws Exception {
                User user = new User();
                while (rs.next()) {
                    user.setAge(rs.getInt("age"));
                    user.setName(rs.getString("name"));
                }
                return user;
            }
        }, null);
        return objects;
    }
}
